// antd 按需加载
import { Toast } from '@ant-design/react-native';

import store from '../../../store/store.js'
import * as ActionTypes from '../../../constants/constants.js'
import { isUser, isWxUser, path, saveData, loadData, removeData, requestMessage } from '../../../util/utils.js'
import request from '../../../api/request.js'

export async function login(options) {
    const { dispatch } = this.props
    const loading = Toast.loading('登录中', 0, null, false)
    const res = await request.MemberController.login(options)
    console.log(res)
    if (res.error) {
        dispatch({
            type: ActionTypes.authError,
            data: res
        })
        return
    }
    return requestMessage(res, loading, {
        success: '登录成功',
        error: '登录失败'
    })
}

export async function globalCodeList(options) {
    const { dispatch } = this.props
    const loading = Toast.loading('加载中', 0, null, false)
    const res = await request.HomeController.globalCodeList(options)
    if (res.error) {
        dispatch({
            type: ActionTypes.globalCodeListError,
            data: res
        })
        return
    }
    dispatch({
        type: ActionTypes.globalCodeList,
        data: res.data.data
    })
    return requestMessage(res, loading)
}
